import 'package:flutter/material.dart';

class Homelist extends StatefulWidget {
  const Homelist({super.key, required this.list});
  final List list;

  @override
  State<Homelist> createState() => _HomelistState();
}

class _HomelistState extends State<Homelist> {
  Widget _getTitleWidget() {
    return Padding(
      padding: const EdgeInsets.fromLTRB(10, 15, 10, 15),
      child: Row(
        children: [
          Image.asset(
            'assets/images/notice@2x.png',
            width: 25,
            height: 25,
          ),
          const Text(
            '社区',
            style: TextStyle(
                color: Colors.black, fontSize: 18, fontWeight: FontWeight.bold),
          ),
          const Text(
            '公告',
            style: TextStyle(
                color: Colors.orange,
                fontSize: 18,
                fontWeight: FontWeight.bold),
          ),
        ],
      ),
    );
  }

  Widget _getListView() {
    return ListView(
      shrinkWrap: true,
      physics: const NeverScrollableScrollPhysics(),
      children: widget.list.map((item) {
        return GestureDetector(
            onTap: () {
              Navigator.pushNamed(context, '/NoticeDetail',
                  arguments: {"id": item["id"]});
            },
            child: Padding(
                padding: const EdgeInsets.all(10),
                child: Container(
                  padding: const EdgeInsets.all(10),
                  decoration: BoxDecoration(
                    color:const Color.fromARGB(255, 111, 143, 63),
                    borderRadius: BorderRadius.circular(10),
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        item['title'],
                        style: const TextStyle(
                            fontSize: 18, fontWeight: FontWeight.bold),
                      ),
                      const SizedBox(
                        height: 10,
                      ),
                      Text(item['content']),
                      Text(item['createdAt']),
                    ],
                  ),
                )));
      }).toList(),
    );
  }

  @override
  Widget build(BuildContext context) {
    return  Container(
      color: Colors.grey[200],
      child: Column(
        
        children: [_getTitleWidget(), _getListView()],
      ),
    );
  }
}
